#include "QuestionEditor.h"
#include "../core/src/container/Question.h"

namespace Xps
{
	QuestionEditor::QuestionEditor(QWidget *parent)
	{
		setObjectName("QuestionEditor");
		QHBoxLayout* box = new QHBoxLayout();
		QVBoxLayout* content_layout = new QVBoxLayout();
		
		setLayout(content_layout);
		
		onechoice = new QRadioButton("One Choice");
		onechoice->setChecked(true);
		multichoice = new QRadioButton("Multiple Choice");

		box->addWidget(onechoice);
		box->addWidget(multichoice);
		box->insertStretch(2,100);

		text = new QTextEdit();
		
				
		content_layout->addWidget(new QLabel("Question:"));
		content_layout->addWidget(text);
		content_layout->addLayout(box);
		content_layout->insertStretch(3,100);
		text->setFocus(Qt::FocusReason::TabFocusReason);
		qDebug() << objectName();
	}

	void QuestionEditor::write(XpsAssets::AssetData* ad)
	{
		XpsAssets::Question* q = (XpsAssets::Question*) ad;

		q->setText(text->toPlainText());
		q->setChoiceMode(onechoice->isChecked() ? 0 : 1);
	}

	void QuestionEditor::read(XpsAssets::AssetData* ad)
	{
		XpsAssets::Question* q = (XpsAssets::Question*) ad;

		text->setText(q->text());
		if (q->choiceMode() == 0)
			onechoice->setChecked(true);
		else
			multichoice->setChecked(true);
	}
}